package service.Impl;

import dao.Impl.PetDaoMySqlImpl;
import dao.Impl.PetDaoOracleImpl;
import dao.PetDao;
import entity.Pet;
import factory.PetDaoFactory;
import org.springframework.stereotype.Service;
import service.PetService;

import javax.annotation.Resource;

@Service("petService")
public class PetServiceImpl implements PetService {
//    PetDao dao= PetDaoFactory.getInstance(PetDaoFactory.defaultBeanName);

    @Resource(type = PetDaoOracleImpl.class)
    private PetDao petDao;

    public PetDao getPetDao() {
        return petDao;
    }

    public void setPetDao(PetDao petDao) {
        this.petDao = petDao;
    }

    @Override
    public boolean save(Pet pet) {
        int rows=petDao.insert(pet);
        delay(3000);
        return rows>0;
    }

    @Override
    public boolean modify(Pet pet) {
        delay(2000);
        return false;
    }

    @Override
    public boolean del(int id) {
        delay(1000);
        return false;
    }

    private void delay(int time){
        try{
            Thread.sleep(time);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
